home *** CD-ROM | disk | FTP | other *** search
Korn shell script | 1997-05-21 | 4.1 KB | 144 lines |
- #! /bin/ksh
- #
- # @(#)java_wrapper.sh 1.27 97/04/28
- #
- #===================================================================
- # THIS SCRIPT AND JAVA WILL NOT RUN UNDER SUNOS4.X, AKA SOLARIS 1.X.
- #===================================================================
-
- function path_warn {
- echo "Warning -- $2 not consistent with the Java home location."
- echo $2 is: $1
- echo JAVA_HOME is: $JAVA_HOME
- if [[ $2 = CLASSPATH ]]
- then
- echo "We recommend not putting any system classes into CLASSPATH."
- echo "(The java invocation script will add these in in the correct place.)"
- else
- if [[ $2 = LD_LIBRARY_PATH ]]
- then
- echo "We recommend not putting any system libraries into LD_LIBRARY_PATH."
- echo "(The java invocation script will add these in in the correct place.)"
- fi
- fi
- }
-
- function check_path {
- if egrep -s '^/usr/java/|:/usr/java/' << EOF
- $1
- EOF
- then
- if ! egrep -s '^/usr/java$|^/usr/java/' << EOF
- $JAVA_HOME
- EOF
- then
- # CLASSPATH or LD_LIBRARY_PATH has components from /usr/java, but
- # java components are not being taken from /usr/java.
- path_warn $1 $2
- fi
- else
- if egrep -s /usr/java/ << EOF
- $1
- EOF
- then
- if egrep -s '^/usr/java$|^/usr/java/' << EOF
- $JAVA_HOME
- EOF
- then
- # CLASSPATH or LD_LIBRARY_PATH has components from /usr/java under an
- # alternate root, but java components are being taken from /usr/java.
- path_warn $1 $2
- fi
- fi
- fi
- }
-
- # Set up default variable values if not supplied by the user.
-
- PRG=`whence $0` >/dev/null 2>&1
- J_HOME=`dirname $PRG`/..
- progname=`basename $0`
-
- # The default THREADS_TYPE is "green_threads". To change the default change
- # the setting of the DEFAULT_THREADS_FLAG variable. The only valid values
- # of that variable are 'green' and 'native'.
- #
- # This introduces a dependency of this wrapper on the policy used to do builds.
- # e.g. the usage of the name "green_threads" here is dependent on the build
- # scripts which use the same name. Since this is somewhat analogous to the
- # wrapper already depending on the build scripts putting the executable in
- # a specific place (JAVA_HOME/bin/`uname -p`), the new dependency does not
- # seem all that bad.
-
- DEFAULT_THREADS_FLAG=green
-
- if [[ ${THREADS_FLAG:-${DEFAULT_THREADS_FLAG}} = native ]] ; then
- THREADS_TYPE=native_threads
- else
- THREADS_TYPE=green_threads
- fi
- export THREADS_TYPE
- #echo "Using executables built for $THREADS_TYPE"
-
- #
- # If the -noenv argument is specified, we set JAVA_HOME
- # and CLASSPATH to nothing, effectively ignoring those
- # environment variables.
- #
- # If one of java's '-*' options was specified on the command line,
- # then ksh insists on trying to interpret the option when
- # we do a set. Worse, it swallows the option, refusing
- # to pass it on to (binary) java. So we keep track of
- # all options and pass them on to eval by hand.
- #
- # Search for '-native' or '-green' flags, and remove them from the
- # arguments if found. Also if found, set THREADS_TYPE to either
- # 'native_threads' or 'green_threads', as appropriate. This is an
- # alternative to using the THREADS_FLAG environment variable to
- # specify the threads package for Solaris.
- #
-
- for a in "$@"; do
- case $a in
- -native)
- echo "-native is not supported in this release."
- exit 1
- ;;
- -green)
- THREADS_TYPE=green_threads
- ;;
- *) newargs="$newargs $a" ;;
- esac
- done
-
- # set $newargs
-
- if [ -z "$JAVA_HOME" ] ; then
- export JAVA_HOME
- JAVA_HOME=$J_HOME
- fi
-
- CLASSPATH="${CLASSPATH-.}"
- check_path $CLASSPATH "CLASSPATH"
- if [ -z "${CLASSPATH}" ] ; then
- CLASSPATH="$JAVA_HOME/classes:$JAVA_HOME/lib/classes.jar:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/i18n.jar:$JAVA_HOME/lib/classes.zip"
- else
- CLASSPATH="$CLASSPATH:$JAVA_HOME/classes:$JAVA_HOME/lib/classes.jar:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/i18n.jar:$JAVA_HOME/lib/classes.zip"
- fi
-
- export CLASSPATH
-
- check_path $LD_LIBRARY_PATH "LD_LIBRARY_PATH"
- LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_HOME/lib/sgi/$THREADS_TYPE"
- export LD_LIBRARY_PATH
-
- prog=$JAVA_HOME/bin/sgi/${THREADS_TYPE}/${progname}
-
- if [ -f $prog ]
- then
- exec $DEBUG_PROG $prog $opts $newargs
- else
- echo >&2 "$progname was not found in ${prog}"
- exit 1
- fi
-